<HTML><HEAD><TITLE>unget(+Stream)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Character I/O</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>unget(+Stream)</H1>
Back up one character on Stream
<DL>
<DT><EM>Stream</EM></DT>
<DD>Integer (stream number) or Atom (reserved or user-defined                symbolic stream name).
</DD>
</DL>
<H2>Description</H2>
    Go back one character on the given Stream. This can be used to
    implement lookaheads.
    <P>
    The number of characters that can be reliably ungotten is 4, and the
    result is only defined if these characters have been read previously.
    <P>
    The result of the operation is undefined if
    <UL>
    <LI>trying to unget more than 4 characters
    <LI>trying to unget more characters than had been read previously
    <LI>trying to unget after a seek operation
    </UL>
    In these cases, unget/1 will succeed, but subsequent read operations
    will return undefined results.

<H3>Modes and Determinism</H3><UL>
<LI>unget(+) is det
</UL>
<H3>Exceptions</H3>
<DL>
<DT><EM>(4) instantiation fault </EM>
<DD>Stream is not instantiated.
<DT><EM>(5) type error </EM>
<DD>Stream is neither an integer nor an atom.
<DT><EM>(192) illegal stream mode </EM>
<DD>Stream not in read mode.
</DL>
<H2>Examples</H2>
<PRE>
% look ahead one character in Stream:

    peek(Stream, X) :-
    	get(Stream, X),
	unget(Stream).
</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/iochar/get-2.html">get / 2</A>, <A HREF="../../kernel/iochar/get_char-2.html">get_char / 2</A>
</BODY></HTML>
